#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
struct Node {
  int ch[2];
  int d[2];
  int w[2];
  int sum;
  bool balanced;
} tr[N];
int tot;
int newnode() {
  ++tot;
  tr[tot].w[0] = tr[tot].w[1] = 0;
  tr[tot].sum = 0;
  tr[tot].d[0] = tr[tot].d[1] = 0;
  tr[tot].ch[0] = tr[tot].ch[1] = 0;
  return tot;
}
int build_tree() {
  int p = newnode();
  cin >> tr[p].w[0] >> tr[p].d[0] >> tr[p].w[1] >> tr[p].d[1];
  if (!tr[p].w[0]) tr[p].ch[0] = build_tree();
  if (!tr[p].w[1]) tr[p].ch[1] = build_tree();
  return p;
}
bool dfs(int p) {
  if (tr[p].ch[0] && !dfs(tr[p].ch[0])) return false;
  if (tr[p].ch[1] && !dfs(tr[p].ch[1])) return false;
  if (!tr[p].w[0]) tr[p].w[0] = tr[tr[p].ch[0]].sum;
  if (!tr[p].w[1]) tr[p].w[1] = tr[tr[p].ch[1]].sum;
  tr[p].sum = tr[p].w[0] + tr[p].w[1];
  return 1ll * tr[p].w[0] * tr[p].d[0] == 1ll * tr[p].w[1] * tr[p].d[1];
}
void solve() {
  tot = 0;
  int root = build_tree();
  bool res = dfs(root);
  if (res)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
    if (t) cout << endl;
  }
  return 0;
}